Imports Cdm.DataCore.UserSecurity
Partial Class AppHeader
    Inherits System.Web.UI.UserControl

    Private Property SettingsList() As Hashtable
        Get
            If ViewState("settingslist") Is Nothing Then
                SetSettingsList()
            End If
            Return ViewState("settingslist")
        End Get
        Set(ByVal value As Hashtable)
            ViewState("settingslist") = value
        End Set
    End Property

    Public Function GetAppSetting(ByVal settingName As String) As String
        If Me.SettingsList(settingName) Is Nothing Then
            Return ""
        Else
            Return Me.SettingsList(settingName).ToString()
        End If

    End Function

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load

        If Not Me.IsPostBack Then

            Me.StateLogo.Style("height") = GetAppSetting("StateLogoHeight")
            Me.StateLogo.Style("top") = GetAppSetting("CCLogoTop")
            Me.StateLogo.ImageUrl = GetAppSetting("StateLogoURL")
            Me.AppNameLabel.Text = GetAppSetting("ApplicationName")
            Me.DeptNameLabel.Text = GetAppSetting("StateDepartmentName")
            Me.AppNameLabel.Style("top") = GetAppSetting("AppNameTop")
            Me.AppNameLabel.Style("font-size") = GetAppSetting("AppNameSize")
            Me.DeptNameLabel.Style("top") = GetAppSetting("StateDeptTop")
            Me.DeptNameLabel.Style("font-size") = GetAppSetting("StateDeptSize")

            If UseLargeToolbar() = False Then

                Me.CCLogo.Visible = False

                'Me.HelpHyperLink.Style("top") = GetAppSetting("CCLogoTop")
                'Me.HelpHyperLink.Visible = True
                Me.NavHelp.Style("top") = GetAppSetting("CCLogoTop")
                Me.NavHelp.Visible = True
                ' Me.ChangePasswordHyperLink.Style("top") = GetAppSetting("CCLogoTop")
                ' Me.ChangePasswordHyperLink.Visible = True

                'Me.LogoutSpan.Style("top") = GetAppSetting("CCLogoTop")
                'Me.LogoutSpan.Visible = True
                Me.NavLogOut.Style("top") = GetAppSetting("AppNameTop")
                Me.NavLogOut.Visible = True

            End If

            If Me.IsParticipantUser Then

                Me.ChangePasswordLink.Visible = False
                Me.HelpImageLink.Visible = False
                Me.LogoutImageLink.Visible = False

            End If

        End If

    End Sub

    Private Function IsParticipantUser() As Boolean

        Select Case (UserAuthorization.CurrentUser.RoleId)

            Case CInt(Role.RoleType.Participant), CInt(Role.RoleType.Representative), CInt(Role.RoleType.LegalGuardian)
                Return True
            Case Else
                Return False

        End Select

    End Function

    Private Sub SetSettingsList()
        Dim pageSettingsList As New Hashtable
        pageSettingsList.Add("ApplicationName", Application("AppName"))
        pageSettingsList.Add("StateDepartmentName", Application("StateDeptName"))
        pageSettingsList.Add("StateLogoURL", Application("CurrentLogo"))

        If UseLargeToolbar() Then
            pageSettingsList.Add("AppNameTop", "16px")
            pageSettingsList.Add("StateDeptTop", "50px")
            pageSettingsList.Add("StateDeptSize", ".75em")
            pageSettingsList.Add("AppNameSize", "1.5em")
            pageSettingsList.Add("StateLogoHeight", "67px")
            pageSettingsList.Add("CCLogoTop", "8px")
        Else
            pageSettingsList.Add("AppNameTop", "10px")
            pageSettingsList.Add("StateDeptTop", "34px")
            pageSettingsList.Add("StateDeptSize", ".7em")
            pageSettingsList.Add("AppNameSize", "1.2em")
            pageSettingsList.Add("StateLogoHeight", "57px")
            pageSettingsList.Add("CCLogoTop", "6px")
        End If

        Me.SettingsList = pageSettingsList
    End Sub

    Private Function UseLargeToolbar() As Boolean

        Select Case UserAuthorization.CurrentUser.RoleId

            Case Role.RoleType.LegalGuardian, Role.RoleType.Representative, Role.RoleType.Participant
                Return True
            Case Else
                Return False

        End Select

    End Function

End Class
